<template>
  <div>
    <el-form :inline="true" :model="ruoyiQuery" class="demo-form-inline">
      <el-form-item label="用户名称">
        <el-input v-model="ruoyiQuery.username" placeholder="请输入用户名称"></el-input>
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input v-model="ruoyiQuery.tel" placeholder="请输入手机号码"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="ruoyiQuery.status" placeholder="状态">
          <el-option label="正常" value="0"></el-option>
          <el-option label="停用" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input v-model="ruoyiQuery.createTime" placeholder="请输入创建时间"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getRuoyi">搜索</el-button>
        <el-button type="primary" @click="openAdd">新增</el-button>
        <el-button type="primary" @click="daochu">导出</el-button>
      </el-form-item>
    </el-form>


    <el-table
        :data="tableData"
        style="width: 100%"
    >
      <el-table-column
          prop="id"
          label="用户编号"
          width="180">
      </el-table-column>
      <el-table-column
          prop="username"
          label="用户名称"
          width="180">
      </el-table-column>
      <el-table-column
          prop="nickName"
          label="用户昵称">
      </el-table-column>
      <el-table-column
          prop="tel"
          label="电话">
      </el-table-column>
      <el-table-column
          prop="status"
          label="状态">
      </el-table-column>
      <el-table-column
          prop="createTime"
          label="创建时间">
      </el-table-column>
      <el-table-column
          prop="name"
          label="部门名称">
      </el-table-column>

      <el-table-column>
        <template v-slot="s">
          <el-button type="text" @click="updateById(s.row.id)">删除</el-button>
          <el-button type="text" @click="openupdate(s.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @current-change="handleCurrentChange"
        :page-size="size"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>

    <el-dialog title="修改" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="用户编号" :label-width="formLabelWidth">
          <el-input v-model="form.id" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="用户名称" :label-width="formLabelWidth">
          <el-input v-model="form.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话" :label-width="formLabelWidth">
          <el-input v-model="form.tel" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-input v-model="form.status" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" :label-width="formLabelWidth">
          <el-input v-model="form.createTime" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="update">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="添加" :visible.sync="dialogFormVisible1">
      <el-form :model="form">
        <el-form-item label="用户编号" :label-width="formLabelWidth1">
          <el-input v-model="form.id" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="用户名称" :label-width="formLabelWidth1">
          <el-input v-model="form.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话" :label-width="formLabelWidth1">
          <el-input v-model="form.tel" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth1">
          <el-input v-model="form.status" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" :label-width="formLabelWidth1">
          <el-input v-model="form.createTime" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "RuoyiView",
  data() {
    return {
      tableData:{},
      ruoyiQuery:{},
      current:1,
      size:1,
      total:0,
      dialogFormVisible:false,
      formLabelWidth:'120px',
      form:{},
      dialogFormVisible1:false,
      form1:{},

      formLabelWidth1:'120px',

    }
  }, methods: {
    handleCurrentChange(current){
      this.current=current;
      this.getRuoyi();
    },
    getNonghuList(){
      this.axios.post("/ruoyi/nongHuList?current="+this.current+"&size="+this.size,this.ruoyiQuery).then(r =>{
        this.tableData=r.data.data.list;
        this.total=r.data.data.total;
      })
    },
    updateById(id){
      this.axios.get("/ruoyi/updateById?id="+id).then(() =>{
        this.$message.success("删除成功");
      })
    },
    openupdate(row){
      this.form=row;
      this.dialogFormVisible=true;
    },
    update(){
      this.axios.get("/ruoyi/update",this.form).then(() =>{
        this.$message.success("修改成功");
        this.dialogFormVisible=false;
        this.getRuoyi();
      })
    },
    openAdd(){
      this.dialogFormVisible1=true;
    },
    add(){
      this.axios.get("/ruoyi/add",this.form1).then(() =>{
        this.$message.success("添加成功");
      })
    },
    daochu(){
      window.location.href="http://localhost:8003/ruoyi/daochuCompany"
    }
  }, created() {
    this.getNonghuList();
  }
}
</script>

<style scoped>

</style>